﻿using System;

namespace Supremacy.Types
{
    [Serializable]
    public abstract class Cloneable : ICloneable
    {
        protected abstract Cloneable CreateInstance();

        public virtual void CloneFrom(Cloneable source) { }

        public static T Clone<T>(T source) where T : Cloneable
        {
            var clone = source.CreateInstance();
            clone.CloneFrom(source);
            return (T)clone;
        }

        #region Implementation of ICloneable

        object ICloneable.Clone()
        {
            return Clone(this);
        }

        #endregion
    }
}